package com.zxn.rv;


import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.LayoutRes;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zxn on 2020-2-22 10:11:56.
 */
public class KMAdapter
        extends BaseQuickAdapter<BaseInfo, KMAdapter.KMHolder> {
    private int mCheckedPositon = -1;

    public void setmCheckedPositon(int mCheckedPositon) {
        this.mCheckedPositon = mCheckedPositon;
    }

    public KMAdapter() {
        super(KMHolder.ITEM_LAYOUT_ID);

    }

    @Override
    protected void convert(KMHolder helper, BaseInfo item) {
        helper.onConvert(item, mCheckedPositon);
    }

    static class KMHolder extends BaseViewHolder {

        private static @LayoutRes
        int ITEM_LAYOUT_ID = R.layout.item_rv_km;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_sub_title)
        TextView tvSubTitle;
        @BindView(R.id.rl)
        RelativeLayout rl;

        KMHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        void onConvert(BaseInfo item, int position) {
            tvTitle.setText(item.num + "公里");
            tvSubTitle.setVisibility(item.show ? View.VISIBLE : View.GONE);
            //sp_rec_r2_c_on

            rl.setBackgroundResource(position == getAdapterPosition() - 1 ? R.drawable.sp_rec_r2_c_on : R.drawable.sp_rec_r2_c_bbbbbb);
            //rl.setBackgroundResource(R.drawable.sp_rec_r2_c_bbbbbb);
        }
    }

}


